package api

import (
	"MxShopApi/service"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/smartwalle/xid"
)

// 支付测试
func OrderPay(ctx *gin.Context) {
	var tradeNo = fmt.Sprintf("%d", xid.Next())
	orderSnc := ctx.DefaultPostForm("orderSnc", tradeNo)
	price := ctx.DefaultPostForm("price", "10")
	PayUrl := service.Pay(orderSnc, price)
	ctx.JSON(200,
		gin.H{
			"Url":     PayUrl,
			"Code":    200,
			"Msg":     "请求成功",
			"Success": true,
		})

}

// 支付宝退款测试
func OrderRefund(ctx *gin.Context) {
	tradeNo := ctx.PostForm("tradeNo")
	refundAmount := ctx.PostForm("refundAmount")
	result := service.Refund(tradeNo, refundAmount)
	ctx.JSON(200, gin.H{
		"data":    result,
		"Code":    200,
		"Msg":     "请求成功",
		"Success": true,
	})
}
